package com.edisoncgh;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class JunitTest {
    @ParameterizedTest
    @CsvSource ({
            "2022-02-05 20:00:00, 0, 2022-02-05 20:10:00, 0, 0.5",
            "2022-02-28 23:50:00, 0, 2022-03-01 00:05:00, 1, 0.75",
            "2022-11-30 23:50:00, 1, 2022-12-01 00:05:00, 0, 0.75",

            "2022-02-05 20:00:00, 0, 2022-02-05 21:00:00, 0, 1.4",
            "2022-02-28 23:50:00, 0, 2022-03-01 00:50:00, 1, 1.4",
            "2022-11-30 23:50:00, 1, 2022-12-01 00:50:00, 0, 1.4",

            "2022-02-05 20:00:00, 0, 2022-02-07 20:00:00, 0, -1",
            "2022-02-28 23:50:00, 0, 2022-03-02 23:50:00, 1, -1",
            "2022-11-30 23:50:00, 1, 2022-12-02 23:50:00, 0, -1"
    })
    public void BillingTest(String startTime, boolean inDayLightSavingOfStartTime,
                            String endTime, boolean inDayLightSavingOfEndTime,
                            BigDecimal excepted) {
        Billing billing = new Billing();

        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime start = LocalDateTime.parse(startTime, dtf);
        LocalDateTime end = LocalDateTime.parse(endTime, dtf);

        long timeLength = billing.calculateTimeSpan(
                start, inDayLightSavingOfStartTime,
                end, inDayLightSavingOfEndTime
        );
        BigDecimal fee = billing.calculateFee(timeLength);
        assertEquals(fee, excepted);
    }
}
